//不需要登陆可访问页面(白名单)
export const whiteList = [
	'/pages/index/index', //首页
	'/pages/student/student', //发现
	'/pages/login/login', //登陆
	'/pages/school_info/school_info', //学校信息
	'/pages/feedback/feedback', //用户反馈
	'/pages/article/article', //文章详细
]

export function hasPermission(url, compulsion = false) {
	// 在白名单中或有token，直接跳转
	url = url.indexOf("?") !== -1 ? url.substring(0, url.indexOf("?")) : url
	if (whiteList.indexOf(url) !== -1 || uni.getStorageSync('token')) {
		return true
	}
	uni.showModal({
		title: '温馨提示',
		content: '您还没有登录！',
		cancelText: compulsion ? '返回首页' : '再看看',
		confirmText: '去登录',
		//showCancel 不显示取消
		success: function(res) {
			if (res.confirm) {
				uni.navigateTo({
					url: '/pages/login/login'
				});
			} else if (res.cancel) {
				if(compulsion){
					//返回首页
					uni.reLaunch({
					    url: '/pages/index/index'
					});
				}
				console.log('再看看');
			}
		}
	});
	return false
}

export function toLogin(){
	uni.showModal({
		title: '温馨提示',
		content: '您还没有登录！',
		cancelText: '返回首页',
		confirmText: '去登录',
		success: function(res) {
			if (res.confirm) {
				uni.navigateTo({
					url: '/pages/login/login'
				});
			} else if (res.cancel) {
				uni.reLaunch({
				    url: '/pages/index/index'
				});
			}
		}
	});
}